<?php

namespace app\controllers;


use Yii;

use yii\data\ArrayDataProvider;

use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;

class IndexController extends Controller
{  
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                // 'only' => ['logout'],
                'rules' => [
                    ['allow' => true,'actions' => ['login', 'error'],],
                    [ 'allow' => true,'actions' => ['logout','index'],'roles' => ['@'],],
                ],
            ],
            
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    public function actionIndex()
    {

//        $news = [];
//        $groups = Member::findAll(['user_id'=>Yii::$app->user->id]);
//        foreach($groups as $group){
////            var_dump($group->project);
////            exit();
//            $events = $group->project->events;
//            $news = array_merge($news,$events);
//        }
//        $newsProvider = new ArrayDataProvider([
//            'allModels' => $news
//        ]);
//
//        //管理员
//        if (Yii::$app->authManager->checkAccess(Yii::$app->user->getId(), 'admin')) {
////             $query = Project::find();
////            $projects = new ActiveDataProvider([
////            'query' => $query,
////            ]);
////            return $this->render('index_admin', [
////                 'projects' => $projects,
////                'news' => $newsProvider
////            ]);
//            
//            $searchModel = new \app\models\MissionSearch();
//            $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
//            
//            return $this->render('index_admin',[
//                'searchModel'=>$searchModel,
//                'dataProvider' => $dataProvider,
//            ]);
//            
//
//        }else if(Yii::$app->authManager->checkAccess(Yii::$app->user->getId(), 'manager')){
//
//            $projects = Project::findByStatusWithCurrentUser(1);
//
//            return $this->render('index_manager', [
//                'projects' => $projects,
//                'news' => $newsProvider
//            ]);
//
//        }else if(Yii::$app->authManager->checkAccess(Yii::$app->user->getId(), 'developer')){
//
//            $missions = Mission::findByStatusWithCurrentUser(1);
//
//            return $this->render('index_developer', [
//                'missions' => $missions,
//                'news' => $newsProvider
//            ]);
//        }

        return $this->render('index');
        



    }

}
